from abc import ABC, abstractmethod
from typing import Any

from task_service.task_context import XycContext, XpcContext, XtwContext, XpmContext


class AbsTaskService(ABC):
    """
    任务抽象类
    """
    name: str = None
    code: str = None
    # 中间结果存储(process产生的数据)
    result: Any = None

    # 上下文
    context: XycContext | XpcContext | XpmContext | XtwContext = None

    def run(self, context):
        self.context = context
        #
        self._pre_process()
        self._process()
        self._post_process()

    def _pre_process(self):
        """
        预处理
        :return:
        """

    @abstractmethod
    def _process(self):
        """
        实际处理
        :return:
        """

    def _post_process(self):
        """
        后处理
        :return:
        """
